<template>
	<view class="content">
        <u-navbar bgColor="#fff" :safeAreaInsetTop="true" :placeholder="true" :fixed="true" 
            @leftClick="back" :title="title">
        </u-navbar>
        <view class="u-flex u-row-between u-p-b-20 headerEle" :style="{top:systemInfo.headerH+'px'}">
            <u--input
                class="search-input u-p-l-30 u-p-r-30"
                fontSize="28rpx"
                v-model="paging.keyWord"
                prefixIcon="search"
                prefixIconStyle="font-size:24px"
                :placeholder="placeholder"
                placeholderStyle="fontSize:28rpx"
                clearable
                border="none"
                @confirm="searchData">
            </u--input>
            <u-button class="search-btn u-m-l-20" type="primary" text="搜索" @tap="searchData"></u-button>
        </view>
        <view style="height:94rpx"></view>


        <!-- 内容 -->
        <view class="uni-area">
            <!-- 提示语(暂时不展示) -->
            <view v-if="page.totalShow&&1==2" class="u-m-t-30 u-font-26">
                在{{total}}个{{title.substring(0,2)}}中搜索到{{page.total}}个{{title.substring(0,2)}}
            </view>

            <!-- 企业 -->
            <uni-item-enterprise class="u-m-t-30" v-if="type=='enterprise'" v-for="(tem,ind) in page.list" :key="ind" :listData="tem" />
            
            <!-- 项目 -->
            <uni-item-project class="u-m-t-30" v-if="type=='project'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" />

            <!-- 班组 -->
            <uni-item-team class="u-m-t-30" v-if="type=='team'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>
            <uni-item-team-member  class="u-m-t-30" v-if="type=='teamMember'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" />

            <!-- 人员 -->
            <uni-item-member class="u-m-t-30" v-if="type=='member'"  
                v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" @memberDetail="clickMember(tem.id)" />

            <!-- 专户 -->
            <uni-item-fohf class="u-m-t-30" v-if="type=='fohf'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>
        
            <!-- 考勤 -->
            <uni-item-attendance class="u-m-t-30" v-if="type=='attendance'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>

            <!-- 工资 -->
            <uni-item-wage class="u-m-t-30" v-if="type=='wage'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>
            <uni-item-wage-member class="u-m-t-30" v-if="type=='wagemember'" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>

            <!-- 现场 -->
            <uni-item-scene class="u-m-t-30" v-if="type=='scene'"  v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" />

            <!-- 预警 -->
            <uni-item-warn class="u-m-t-30" v-if="type=='warn'"  v-for="(tem,ind) in page.list" :key="ind" :listItem="tem" />

            <!-- 返回顶部 -->
            <u-back-top :scroll-top="page.scrollTop" @tap="toTop"></u-back-top>
            <!-- 加载更多 -->
            <u-loadmore :status="page.status" />
        </view>

        <!-- 提示组件 -->
        <u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                // 设备信息
                systemInfo: uni.getStorageSync('systemInfo'),
                total: 0, // 当前搜索内容的总数(暂时不展示)

                type: 'enterprise', // 一级参数,默认为企业管理
                title: '搜索',
                placeholder: '请输入关键字查询信息',
                api: {}, // 搜索api

                // 辅助参数
                assist: null, 

                // 分页相关参数
                paging:{
                    pageNum: 1,
                    pageSize: this.$config.pageSize,
                    keyWord: '',
                },
                page:{
                    totalShow: false, // 搜索结果提示(暂时不展示)
                    scrollTop: 0,
                    status: 'nomore',
                    total: 0,
                    list: [], // 列表
                }
			}
		},


        onPageScroll(e) {
            this.page.scrollTop = e.scrollTop;
        },
        onReachBottom(){
            if( this.page.list.length < this.page.total ){
                this.paging.pageNum += 1
                this.page.status = 'loading'
                this.getData()
            }else{
                this.page.status = 'nomore'
            }
        },


		onLoad(option) {
            this.type = option.type
            // this.total = option.total // 搜索结果(暂时不显示)
            if( option.assist )  this.assist = option.assist
            switch (option.type) {
                case 'enterprise':
                    this.title = '单位管理' // 企业管理
                    this.placeholder = '请输入单位名称/统一信用代码查询信息'
                    this.api = this.$apis.entList
                    break;
                case 'project':
                    this.title = '项目管理'
                    this.placeholder = '请输入项目名称查询信息'
                    this.api = this.$apis.proProjectList
                    break;
                case 'team':
                    this.title = '班组管理'
                    this.placeholder = '请输入班组名称/班组长查询信息'
                    this.api = this.$apis.teamList
                    break;
                case 'teamMember':
                    this.title = '班组成员'
                    this.placeholder = '请输入成员姓名/证件号码查询信息'
                    this.api = this.$apis.teamStaff
                    this.paging['id'] = option.id // 班组Id【必传】
                    break;
                case 'member':
                    this.title = '人员搜索'
                    this.placeholder = '请输入人员姓名/证件号码查询信息'
                    this.api = this.$apis.staffList
                    break;
                case 'fohf':
                    this.title = '专户搜索'
                    this.placeholder = '请输入专户名称/项目名称查询'
                    this.api = this.$apis.fohfAccountList
                    break;
                case 'attendance':
                    this.title = '考勤管理'
                    this.placeholder = '请输入项目名称查询信息'
                    this.api = this.$apis.kqList
                    break;
                case 'wage':
                    this.title = '工资管理'
                    this.placeholder = '请输入项目名称查询信息'
                    this.api = this.$apis.wgWageManage
                    break;
                case 'wagemember': // 工资发放详情(发放人员列表)
                    this.title = '工资管理'
                    this.placeholder = '请输入姓名查询信息'
                    this.api = this.$apis.wgWageMemberList
                    this.paging['ywbh'] = option.ywbh // 发放业务编号【必传】
                    break;
                case 'scene':
                    this.title = '现场管理'
                    this.placeholder = '请输入查询信息'
                    this.api = this.$apis.scEquipmentList
                    break;
                case 'warn':
                    this.title = '预警'
                    this.placeholder = '请输入项目名称查询信息'
                    this.api = this.$apis.warningList
                    break;
                case 'supervise':
                    this.title = '督办'
                    this.placeholder = '请输入项目名称查询信息'
                    this.api = this.$apis.dubanList
                    break;
            }
		},


		methods: {
            // 返回
            back(){
                uni.navigateBack()
            },
            // 搜索
            searchData(){
                this.paging.pageNum = 1
                this.page.list = []
                this.toTop()
                this.getData()
            },
            // 获取数据
            getData(){
                uni.showLoading({ title:'搜索中' })
                // 考勤搜索的关键词为xmmc
                if( this.type == 'attendance' ) this.paging['xmmc'] = this.paging.keyWord 
                // 预警督办搜索的关键词为gcmc
                if( this.type == 'warn' || this.type == 'supervise' ) this.paging['gcmc'] = this.paging.keyWord 
                // console.log('搜索参数',this.paging)
                this.$request(this,this.api,this.paging).then(res=>{
                    // console.log('搜索到的数据',res)
                    // this.page.totalShow = true // 搜索结果(暂时不显示)
                    this.page.total = res.total
                    if( res.total && res.total != 0 ){
                        res.data.map((v,i)=>{
                            this.page.list.push(v)
                        })
                    }else{
                        uni.$u.toast('暂未查询到更多相关数据')
                    }
                    if( res.total > 20 ){
                        this.page.status = 'loadmore'
                    }else{
                        this.page.status = 'nomore'
                    }
                }).then()
            },

            // 点击人员
            clickMember(id){
                if( this.assist=='info'){ // 查看人员详情
                    uni.navigateTo({ url: '/pages/member-bag/detail?id='+id })
                }
                if( this.assist =='kaoqin'){ // 查看人员考勤
                    uni.navigateTo({ url: '/pages/attendance-bag/particulars' })
                }
            },

            // 回到顶部
            toTop(){
                uni.pageScrollTo({ scrollTop: 0, duration: 300 })
            }
		}
	}
</script>

<style lang="scss">
    .headerEle{
        width: 100%;
        position: fixed !important;
        left: 0;
        .search-input{
            width: 534rpx !important;
            box-sizing: border-box;
            height: 74rpx;
            background: #F6F7F8;
        }
        .search-btn{
            width: 136rpx;
            height: 74rpx;
            font-size: 28rpx;
        }
    }
</style>
